import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { VideoState } from './type'



const useStore = create(
    persist<VideoState>(
        (set) => ({
            Init: {
                Type: '',
                Srt: '',
                VideoUrl: '',
                Image: '',
                BackgroundColor: ''
            },
            isPlaying: false,
            peoplestart: false,
            setpeoplestart: (peoplestart: boolean) => set(() => ({ peoplestart })),
            setInit: (key, value) => set((state) => {
                const data = { ...state.Init };
                if (key !== 'Srt') {
                    data.Type = key;
                }
                data['Image'] = ''
                data['VideoUrl'] = ''
                data['BackgroundColor'] = ''
                data[key] = value;
                return { Init: data };
            }),
            setVideoControl: (control) =>
                set((state) => ({ ...state, ...control })),
        }),
        {
            name: 'video-storage',
            partialize: (state) => state,
        }
    )
);

export default useStore;